﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace Fis.Win.Forms
{
    public partial class LoadingForm : DevExpress.XtraEditors.XtraForm
    {
        public LoadingForm()
        {
            InitializeComponent();
        }


        public static void ShowLoading(Action action, Form owner)
        {
            using (var f = new LoadingForm())
            {
                AsyncCallback callback = f.Callback;
                var ar = action.BeginInvoke(callback, null);
                f.ShowDialog(owner);
                action.EndInvoke(ar);
            }
            
        }

        void Callback(IAsyncResult ar)
        {
            Fis.Win.Utils.UIUtils.MainForm.Invoke(LoadingClose());
        }

        Delegate LoadingClose()
        {
            return new Action(() => Close());
        }
    }
}